package com.ruoyi.make.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ruoyi.make.domain.KsMerchants;
import com.ruoyi.make.domain.ScddProductionOrderForm;
import com.ruoyi.make.service.IScddProductionOrderFormService;
import com.ruoyi.make.service.KsMerchantsService;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产订单Controller
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/form")
public class ScddProductionOrderFormController extends BaseController
{
    @Resource
    private IScddProductionOrderFormService scddProductionOrderFormService;

    @Resource
    private KsMerchantsService ksMerchantsService;
    /**
     * 查询生产订单列表
     */
    @RequiresPermissions("scdd:form:list")
    @GetMapping("/list")
    public TableDataInfo list(ScddProductionOrderForm scddProductionOrderForm)
    {
        startPage();
        List<ScddProductionOrderForm> list = scddProductionOrderFormService.findAll(scddProductionOrderForm);
        System.out.println(JSON.toJSONString(getDataTable(list)));
        return getDataTable(list);
    }

    /**查询客商列表*/
    @RequiresPermissions("scdd:form:merchants")
    @GetMapping("/merchants")
    public TableDataInfo merchantsList(@RequestParam(required = false)String ksName)
    {
        startPage();
        List<KsMerchants> merchants=ksMerchantsService.findAll(ksName);
        return getDataTable(merchants);
    }
    /**
     * 导出生产订单列表
     */
//    @RequiresPermissions("scdd:form:export")
//    @Log(title = "生产订单", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ScddProductionOrderForm scddProductionOrderForm)
//    {
//        List<ScddProductionOrderForm> list = scddProductionOrderFormService.selectScddProductionOrderFormList(scddProductionOrderForm);
//        ExcelUtil<ScddProductionOrderForm> util = new ExcelUtil<ScddProductionOrderForm>(ScddProductionOrderForm.class);
//        util.exportExcel(response, list, "生产订单数据");
//    }

    /**
     * 获取生产订单详细信息
     */
    @RequiresPermissions("scdd:form:details")
    @GetMapping(value = "/details/{ddCode}")
    public AjaxResult getInfo(@PathVariable("ddCode") String ddCode)
    {
        System.out.println(ddCode);
        return AjaxResult.success(scddProductionOrderFormService.ddByCode(ddCode));
    }

    /**
     * 新增生产订单
     */
    @RequiresPermissions("scdd:form:add")
    @Log(title = "生产订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ScddProductionOrderForm scddProductionOrderForm)
    {
        System.out.println("进来了-------------------------");
        return toAjax(scddProductionOrderFormService.insertScddProductionOrderForm(scddProductionOrderForm));
    }

    /**
     * 修改生产订单
     */
    @RequiresPermissions("scdd:form:edit")
    @Log(title = "生产订单", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ScddProductionOrderForm scddProductionOrderForm)
    {
        return toAjax(scddProductionOrderFormService.updateScddProductionOrderForm(scddProductionOrderForm));
    }

    /**
     * 删除生产订单
     */
    @RequiresPermissions("scdd:form:remove")
    @Log(title = "生产订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ddCodes}")
    public AjaxResult remove(@PathVariable String[] ddCodes)
    {
        return toAjax(scddProductionOrderFormService.deleteScddProductionOrderFormByDdCodes(ddCodes));
    }
}
